//------------------------------------------------------------------------------
// <copyright file="RpcResponse.h" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

#pragma once

#include <RpcServer.h>
#include <RpcArchiveImpl.h>

namespace Microsoft { namespace Internal { namespace GamesTest { namespace Rpc { namespace Server
{
	/// <summary>
	/// This class represents the response to an RpcRequest.
	/// </summary>
	class RpcResponse
	{
	private:
		RpcArchiveImpl m_archive;
		RpcHookCode m_hookErrorCode;
		HRESULT m_rpcErrorCode;
		RequestIdType m_requestId;

	public:
		/// <summary>
		/// Initializes a new instance of the RpcResponse class.
		/// </summary>
		RpcResponse()
			: m_hookErrorCode(S_OK)
			, m_rpcErrorCode(S_OK)
		{
		}

		/// <summary>
		/// Gets the data to be sent back to the client.
		/// </summary>
		RpcArchiveImpl& GetArchive()
		{
			return m_archive;
		}

		/// <summary>
		/// Gets the data to be sent back to the client.
		/// </summary>
		__declspec(property(get=GetArchive)) RpcArchiveImpl& Archive;

		/// <summary>
		/// Gets the user-defined error code returned by a hook method.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library users to send back their return value.
		/// </remarks>
		RpcHookCode GetHookErrorCode()
		{
			return m_hookErrorCode;
		}

		/// <summary>
		/// Sets the user-defined error code returned by a hook method.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library users to send back their return value.
		/// </remarks>
		void SetHookErrorCode(RpcHookCode errorCode)
		{
			m_hookErrorCode = errorCode;
		}

		/// <summary>
		/// Gets or sets the user-defined error code returned by a hook method.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library users to send back their return value.
		/// </remarks>
		__declspec(property(get=GetHookErrorCode,put=SetHookErrorCode)) RpcHookCode HookErrorCode;

		/// <summary>
		/// Gets an error code generated by TDK RPC during the handling of the RpcRequest.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library coders to send back Tdk Rpc errors.
		/// </remarks>
		HRESULT GetRpcErrorCode()
		{
			return m_rpcErrorCode;
		}

		/// <summary>
		/// Sets an error code generated by TDK RPC during the handling of the RpcRequest.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library coders to send back Tdk Rpc errors.
		/// </remarks>
		void SetRpcErrorCode(HRESULT errorCode)
		{
			m_rpcErrorCode = errorCode;
		}

		/// <summary>
		/// Gets or sets an error code generated by TDK RPC during the handling of the RpcRequest.
		/// </summary>
		/// <remarks>
		/// This error code should only be used by library coders to send back Tdk Rpc errors.
		/// </remarks>
		__declspec(property(get=GetRpcErrorCode,put=SetRpcErrorCode)) HRESULT RpcErrorCode;

		RequestIdType GetRequestId()
		{
			return m_requestId;
		}

		void SetRequestId(RequestIdType requestId)
		{
			m_requestId = requestId;
		}

		/// <summary>
		/// Gets and sets the Id of this request.
		/// </summary>
		__declspec(property(get=GetRequestId, put=SetRequestId)) RequestIdType RequestId;

		/// <summary>
		/// Serializes this object to the given JsonObject.
		/// </summary>
		GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT Serialize(std::wstring& result);

		/// <summary>
		/// Parse a string into the given object.
		/// </summary>
		/// <remarks>This is currently used only for tests, has no effect on functionality.</remarks>
		static GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT Parse(const wchar_t* data, RpcResponse* response);
	};

}}}}}